import BasicConfig from "@/utils/config"
import AMap from "@/utils/amap"
/**
 * @param {String} type : gcj02 wgs84
 */
export const useWxFuzzyLocation = (type = "wgs84") => {
	return new Promise((resolve, reject) => {
		wx.getFuzzyLocation({
			type,
			success: function(res) {
				resolve(res)
				console.log('useFuzzyLocation', res);
				// _this.ml_markers.push({
				// 	id: uni.$u.guid(),
				// 	latitude: res.latitude,
				// 	longitude: res.longitude
				// })
				// _this.form[formKeys.lat] = res.latitude;
				// _this.form[formKeys.lon] = res.longitude;
				// const location = res.longitude + ',' + res.latitude;
			},
			fail(err) {
				reject(err)
				console.error('FuzzyLocation[fail]', err);
			}
		})
	})
}

/**
 * @param {String} type : gcj02 wgs84
 */
export const useWxGetLocation = (type = "gcj02") => {
	return new Promise((resolve, reject) => {
		wx.getLocation({
			type,
			success: function(res) {
				resolve(res)
				console.log('useGetLocation', res);
				// _this.ml_markers.push({
				// 	id: uni.$u.guid(),
				// 	latitude: res.latitude,
				// 	longitude: res.longitude
				// })
				// _this.form[formKeys.lat] = res.latitude;
				// _this.form[formKeys.lon] = res.longitude;
				// const location = res.longitude + ',' + res.latitude;
			},
			fail(err) {
				reject(err)
				console.error('GetLocation[fail]', err);
			}
		})
	})
}

export const useChooseLocation = ({
	lat,
	lon
}) => {
	return new Promise((resolve, reject) => {
		uni.chooseLocation({
			longitude: lon,
			latitude: lat,
			success(res) {
				console.log("手动获取位置信息", res);
				// me.form[formKeys.eventLocation] = res.address;
				resolve(res)
			},
			fail(err) {
				console.error("手动获取位置信息err", err);
				reject(err)
			}
		});
	})
}

export const useAmapGetRegeo = (location) => {
	return new Promise((resolve, reject) => {
		AMap.getRegeo({
			location,
			success: (res) => {
				resolve(res)
				console.log("获取指定定位信息(高德)", res)
			},
			fail: err => {
				reject(err)
				console.error('AmapGetRegeo[fail]', err);
			}
		})
	})
}